package com.xbongbong.saas.model.impl;

import com.xbongbong.message.domain.entity.PushSetEntity;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.domain.dao.WorkOrderEvaluateDao;
import com.xbongbong.saas.domain.entity.WorkOrderEvaluateEntity;
import com.xbongbong.saas.domain.entity.ext.WorkOrderEvaluateRateStarEntityExt;
import com.xbongbong.saas.model.WorkOrderEvaluateModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author 刘阳
 * @date 2019/4/15 11:18 AM
 * @since v1.0
 * @version v1.0
 */
@Service("WorkOrderEvaluateModel")
public class WorkOrderEvaluateModelImpl implements WorkOrderEvaluateModel {

    @Resource
    private WorkOrderEvaluateDao workOrderEvaluateDao;

    @Override
    public Integer insert(WorkOrderEvaluateEntity entity) throws XbbException {
        long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return workOrderEvaluateDao.insert(entity);
    }

    @Override
    public Integer update(WorkOrderEvaluateEntity entity) throws XbbException {
        return workOrderEvaluateDao.update(entity);
    }

    @Override
    public List<WorkOrderEvaluateEntity> findEntitys(Map<String, Object> param){

        return workOrderEvaluateDao.findEntitys(param);

    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return workOrderEvaluateDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public WorkOrderEvaluateEntity getByKey(Long key, String corpid){
        return workOrderEvaluateDao.getByKey(key,corpid);
    }

    @Override
    public WorkOrderEvaluateEntity getByWorkOrderId(Long workOrderId, String corpid) {
        return workOrderEvaluateDao.getByWorkOrderId(workOrderId,corpid);
    }

    @Override
    public List<WorkOrderEvaluateRateStarEntityExt> getRateStarCount(Map<String, Object> param) {
        return workOrderEvaluateDao.getRateStarCount(param);
    }

    @Override
    public List<WorkOrderEvaluateRateStarEntityExt> evaluateListByWorkOrderIdSet(String corpid, Set<Long> workOrderIdSet) {
        Map<String, Object> param = new HashMap<>(3);
        param.put("corpid", corpid);
        param.put("del", DelEnum.NORMAL.getDel());
        param.put("workOrderIdIn", workOrderIdSet);
        return getRateStarCount(param);
    }

    @Override
    public Integer save(WorkOrderEvaluateEntity workOrderEvaluateEntity) throws XbbException {
        if (workOrderEvaluateEntity.getId() ==  null || workOrderEvaluateEntity.getId().equals(0L)) {
            return insert(workOrderEvaluateEntity);
        }
        return update(workOrderEvaluateEntity);
    }

}
